package com.geng.io.netty;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class EchoHandler extends SimpleChannelInboundHandler {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf buf = (ByteBuf)msg;
        byte[] req = new byte[buf.readableBytes()];
        System.out.println(ctx.channel());
        buf.readBytes(req);
        String body = new String(req,"utf-8");
        System.out.println(body);
        body = body + "我不好";
        ByteBuf resp = Unpooled.copiedBuffer(body.getBytes());
        ctx.write(resp);
        ctx.flush();
    }
}
